<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>注册登录页面</title>
	<script src="http://lib.sinaapp.com/js/jquery/2.2.4/jquery-2.2.4.min.js"></script>
	<script>
        function doWithReult(obj){
            obj=obj.replace(/,/g,",<br />");
            obj=obj.replace(/{/g,"{<br/>");
            obj=obj.replace(/}/g,"<br/>}");
            $("#jsonDataView").html(obj);
        }
        /********************** 注册 start *****************************/
        //验证码发送
       function getVerifyCode(type){
          var account=$("#loginName").val();
           var aj = $.ajax( {
               url:'/user/getVerifyCode.do',// 跳转到 action
               data:{
                   account : account,
                   type:type
               },
               type:'post',
               cache:false,
               dataType:'text',
               success:function(data) {
                   doWithReult(data.toString());
               },
               error : function() {
                   // view("异常！");
                   alert("异常！");
               }
           });
       }
        //验证码验证
        function verifyCode(){
            var account=$("#loginName").val();
            var code=$("#smsCode").val();
            var aj = $.ajax( {
                url:'/user/verifyCode.do',// 跳转到 action
                data:{
                    account : account,
                    code:code
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }

        //注册
        function register(type){
            var account=$("#loginName").val();
            var password=$("#plainPassword").val();

            var aj = $.ajax( {
                url:'/user/register.do',
                data:{
                    account : account,
                    password:password,
                    type:type
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());;
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }
        /********************** 注册 end *****************************/
        /********************** 登录 start *****************************/
        //登录
        function login(){
            var account=$("#loginName").val();
            var password=$("#plainPassword").val();
            var aj = $.ajax( {
                url:'/user/login.do',// 跳转到 action
                data:{
                    account : account,
                    password:password
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());;
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }
        //修改密码
        function updatePass(){
            var account=$("#loginName").val();
            var password=$("#plainPassword").val();
            var oldPass=$("#pwdRepeat").val();
            var aj = $.ajax( {
                url:'/user/updatePwd.do',
                data:{
                    account : account,
                    oldPassword:oldPass,
                   password:password
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());;
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }
        function checkToken(){
            var token=$("#token").val();
            var role=$("#role").val();

            var aj = $.ajax( {
                url:'/verify/token.do',
                data:{
                    role : role,
                    token:token
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());;
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }

        function addGameRole(){
            var serviceId=$("#serviceId").val();
            var roleName=$("#roleName").val();
            var account=$("#loginName").val();
            var aj = $.ajax( {
                url:'/game/roles/addrole.do',
                data:{
                    account : account,
                    serviceId:serviceId,
                    roleName:roleName
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());;
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }

        function logout(){
            var token=$("#token").val();
            var account=$("#loginName").val();
            var aj = $.ajax( {
                url:'/user/loginout.do',
                data:{
                    account : account,
                    token:token
                },
                type:'post',
                cache:false,
                dataType:'text',
                success:function(data) {
                    doWithReult(data.toString());;
                },
                error : function() {
                    // view("异常！");
                    alert("异常！");
                }
            });
        }



	</script>
</head>

<body>


		<fieldset>
            <legend><small>接口说明： </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;发送验证码  1 输入验证码 2 点击获取验证码 </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;验证码验证 1.在验证码处输入收到的验证码 2 点击验证验证码 </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;注册 1.在密码处输入密码  2 点击注册 </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;登录 1.在密码处输入密码  2 点击登录 </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;退出 1. 输入账号 ，token处输入token  2 点击退出 </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;私服-登录器token验证 1.token处输入token  2 点击私服-登录服务器token验证 </small></legend>
            <legend><small>&nbsp;&nbsp;&nbsp;&nbsp;添加私服角色名称 1.输入账号，输入私服id,输入角色名称  2 点击添加游戏私服角色 </small></legend>

            <div class="control-group">
				<label for="loginName" class="control-label">登录名:</label>
				<div class="controls">
					<input type="text" id="loginName" name="loginName" class="input-large required" minlength="3"/>
				</div>
			</div>
            <div class="control-group">
                <label for="smsCode" class="control-label">验证码:</label>
                <div class="controls">
                    <input type="text" id="smsCode" name="smsCode" class="input-large required"/>
                </div>
            </div>
			<div class="control-group">
				<label for="plainPassword" class="control-label">密码:</label>
				<div class="controls">
					<input type="password" id="plainPassword" name="plainPassword" class="input-large required"/>
				</div>
			</div>
            <div class="control-group">
                <label for="pwdRepeat" class="control-label">确认密码/旧密码:</label>
                <div class="controls">
                    <input type="password" id="pwdRepeat" name="pwdRepeat" class="input-large required"/>
                </div>
            </div>
            <div class="control-group">
                <label for="token" class="control-label">token:</label>
                <div class="controls">
                    <input type="text" id="token" name="token" class="input-large required" style="width: 500px;"/>
                </div>
            </div>
            <div class="control-group">
                <label for="serviceId" class="control-label">私服ID:</label>
                <div class="controls">
                    <input type="text" id="serviceId" name="serviceId" class="input-large required" style="width: 500px;"/>
                </div>
            </div>
            <div class="control-group">
                <label for="roleName" class="control-label">角色名称:</label>
                <div class="controls">
                    <input type="text" id="roleName" name="roleName" class="input-large required" style="width: 500px;"/>
                </div>
            </div>
            <div   class="control-group" style="text-align:left;height: 200px;">
                <label for="pwdRepeat" class="control-label">json串如下:</label>
                <div class="controls" id="jsonDataView" style="border: 1px solid darkgray;">

                </div>
            </div>
			<div class="form-actions">
                <input id="getcode" class="btn" type="button" value="获取注册验证码" onclick="getVerifyCode(1)"/>
                <input id="getPassResetCode" class="btn" type="button" value="获取密码重置验证码" onclick="getVerifyCode(2)"/>
                <input id="getPassUpdateCode" class="btn" type="button" value="获取修改密码验证码" onclick="getVerifyCode(3)"/>
                <input id="verify" class="btn" type="button" value="验证验证码" onclick="verifyCode()"/>

                <input id="register" class="btn" type="button" value="注册" onclick="register(1)"/>
                <input id="reset" class="btn" type="button" value="重置" onclick="register(2)"/>

                <input id="login" class="btn" type="button" value="登录" onclick="login()"/>
                <input id="updatePass" class="btn" type="button" value="修改密码" onclick="updatePass()"/>

                <input id="logout" class="btn" type="button" value="退出" onclick="logout()"/>

                <input id="checkToken" class="btn" type="button" value="私服-登录服务器token验证" onclick="checkToken()"/>
                <input id="addGameRole" class="btn" type="button" value="添加游戏私服角色" onclick="addGameRole()"/>
			</div>
		</fieldset>

</body>
</html>